package com.example.shop.modules.manage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.shop.modules.manage.service.IGoodsTypeAdminService;
import com.example.shop.persistence.entity.GoodsType;
import com.example.shop.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.example.shop.utils.JSONResult.renderSuccess;

@Api(tags = "后台接口商品分类管理")
@RestController
@RequestMapping("/manage/goodsType")
public class GoodsTypeAdminController {
    @Autowired
    IGoodsTypeAdminService goodsTypeService;

    @ApiOperation(value = "新增或修改商品分类",notes = "有id则为修改")
    @PostMapping("/add")
    public JSONResult insertGoodsType(GoodsType goodsType){
        return renderSuccess(goodsTypeService.saveOrUpdate(goodsType));
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete/{id}")
    public JSONResult deleteGoodsType(@PathVariable("id") Integer id){
        return renderSuccess(goodsTypeService.deleteGoodsType(id));
    }

    @ApiOperation(value = "查询分类列表",notes = "查询商品全部分类，不分页，不分级")
    @GetMapping("/list")
    public JSONResult getGoodsTypeList(){
        List<GoodsType> list = goodsTypeService.list();
        return renderSuccess(list);
    }

}
